// let toico = ''
//     //获取头像
// function uploadImg(user_ico) {
//     let v = document.getElementById('timg')
//         //a.value, 看起来像一个字符串，但是它是文件file类型的。
//     var xhr = new XMLHttpRequest()
//     xhr.open("post", "http://39.106.207.209:8100/clansman/uploads")
//         //不能把文件格式破坏了，所以传文件时不需要这一行
//         //xhr.setRequestHeader("Content-Type", "application/json")
//     xhr.onreadystatechange = function() {
//             if (xhr.readyState == 4 && xhr.status == 200) {
//                 //let clansList = JSON.parse(xhr.responseText)
//                 // console.log(xhr.responseText);
//                 toico = xhr.responseText
//                 let d = 'http://39.106.207.209:8100/clansman' + xhr.responseText
//                 v.setAttribute('src', d)
//             }
//         }
//         //formdata格式   ；input对象.files[0] 表示获取文件
//     let fd = new FormData();
//     fd.append("file", user_ico.files[0]); //第一个参数：Key，第二个参数：形参.files[0]
//     xhr.send(fd)
// }
// // 点击确定添加家人事件    添加
// function ensure() {
//     let xing = document.querySelector('#xing')
//     let ming = document.querySelector('#ming')
//     let dianhua = document.querySelector('#dianhua')
//     let geyan = document.querySelector('#geyan')
//     let xingbie = $("input[name='gender']:checked").val();
//     let riqi = $("#riqi").val()

//     var xhr = new XMLHttpRequest()
//     xhr.open("post", "http://39.106.207.209:8100/family/addFamily")
//     xhr.setRequestHeader("Content-Type", "application/json")
//     xhr.onreadystatechange = function() {
//         if (xhr.readyState == 4 && xhr.status == 200) {
//             let clansList = JSON.parse(xhr.responseText)
//                 // console.log(clansList);
//             if (clansList.code == 1) {
//                 location.href = "ethnic.html"
//             } else {
//                 alert("添加家人失败")
//             }
//         }
//     }
//     let a = {
//         surname: xing.value,
//         name: ming.value,
//         gender: xingbie,
//         birth_greg: riqi,
//         phone: dianhua.value,
//         life_motto: geyan.value,
//         headimg: toico
//     }
//     let b = JSON.stringify(a)
//     xhr.send(b);
// }

let toico = ''
    //获取头像
function uploadImg(user_ico) {
    let v = document.getElementById('timg')
    let fd = new FormData();
    fd.append("file", user_ico.files[0]);
    $.ajax({
        url: 'http://39.106.207.209:8100/clansman/uploads',
        type: 'post',
        data: fd,
        processData: false, //不处理数据
        contentType: false, //不设置内容类型
        success(res) {
            // console.log(res);
            toico = res
            let d = 'http://39.106.207.209:8100/clansman' + res
            v.setAttribute('src', d)
        }
    })
}
// 新增
function ensure() {
    let xing = document.querySelector('#xing')
    let ming = document.querySelector('#ming')
    let dianhua = document.querySelector('#dianhua')
    let geyan = document.querySelector('#geyan')
    let xingbie = $("input[name='gender']:checked").val();
    let riqi = $("#riqi").val()

    let a = {
        surname: xing.value,
        name: ming.value,
        gender: xingbie,
        birth_greg: riqi,
        phone: dianhua.value,
        life_motto: geyan.value,
        headimg: toico
    }
    let b = JSON.stringify(a)
    $.ajax({
        type: 'post',
        url: 'http://39.106.207.209:8100/family/addFamily',
        data: b,
        contentType: "application/json;charset=UTF-8", //指定消息请求类型
        success(res) {
            // console.log(res);
            if (res.code == 1) {
                location.href = "ethnic.html"
            } else {
                alert("添加家人失败")
            }
        }
    })
}